/* 
 * File:   TimestampControl.h
 * Author: lusitanio
 *
 * Created on 8 de Abril de 2012, 20:50
 */

#ifndef TIMESTAMPCONTROL_H
#define	TIMESTAMPCONTROL_H
#include <iostream>
using namespace std;


// Tipo de Timestamp

enum TimestampType {
    DATA,
    QUERY
};

class TimestampControl {
private:
    int type_;
    double actual_data_timestamp_;
    double last_data_timestamp_;
    float frequency_;

public:

    TimestampControl(int t, double atimestamp = 0.0) {
        type_ = t;
        actual_data_timestamp_ = atimestamp;
        last_data_timestamp_ = atimestamp;
        frequency_ = 1;
    }

    TimestampControl() {

    }

    void addTimestamp(double time) {
        actual_data_timestamp_ = time;
        double dif = (actual_data_timestamp_ - last_data_timestamp_);

        dif == 0.0 ? dif = 1 : dif = dif;
        frequency_ = 1 / dif;
        //printf("DIF: %f FREQ: %f\n",dif,frequency_);
        last_data_timestamp_ = actual_data_timestamp_;
    }

    float getFrequency() {
        return frequency_;
    }

    void print() {
        printf("Timestamp%s Frequency: %f\n", returnTypeDesc(), frequency_);
    }

    void print(int s) {
        printf("Timestamp%s[%d] Frequency: %f\n",returnTypeDesc(), s, frequency_);
    }

    char * returnTypeDesc(){
        char * tipo;
        switch (type_) {
            case TimestampType(DATA):
                tipo="DATA";
                break;
            case TimestampType(QUERY):
                tipo="QUERY";
                break;
            default:
                tipo="";
                break;
        }        
        return tipo;
    }

};


#endif	/* TIMESTAMPCONTROL_H */

